package cn.edu.bcu.ls.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.bcu.ls.entity.Course;
import cn.edu.bcu.ls.entity.Have;
import cn.edu.bcu.ls.serviceImpl.HaveService;
import io.swagger.annotations.ApiOperation;

@RestController
public class HaveController {
	@Autowired
	private HaveService haveService;
	/**
	 * 添加收藏
	 * @param have
	 */
	@ApiOperation(value = "添加收藏")
	@PostMapping(value="Have")
	public boolean insertCourse(Have have) {
		if (haveService.insert(have) >0) {
			return true;
		}else {
			return false;
		}
	}
	
	
	/**
	 * delete already subscribe course
	 * @param String uId,Integer cId
	 */
	@ApiOperation(value = "删除收藏，传入用户id(u_id)和课程id(c_id)")
	@DeleteMapping(value="Have/{u_id}&{c_id}")
	public boolean deleteByPrimaryKey(@PathVariable("u_id") String uId,@PathVariable("c_id") Integer cId) {
		if (haveService.deleteByPrimaryKey(uId,cId) >0) {
			return true;
		}else {
			return false;
		}
	}
	
	
	/**
	 * According uId query all content of subscription 根据uId返回该用户的收藏夹
	 */
	@ApiOperation(value = "根据uId返回该用户的收藏夹")
	@GetMapping(value="Have/queryHave/{u_id}")
	public List selectByPrimaryKey(@PathVariable("u_id") String uId) {
		List courses = haveService.selectByPrimaryKey(uId);
		System.out.print(courses);
		return courses;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
